package com.wuyou.designPatterns.iterator;

import java.util.ArrayList;
import java.util.List;

public class BookShelfList<T> implements Aggregate<T>{

    private List<T> bookList;

    private Iterator<T> iterator;

    private int last = 0;

    public BookShelfList() {
    }

    public BookShelfList(int initialCapacity) {
        this.bookList = new ArrayList<>(initialCapacity);
    }

    public void append(T t){
        this.bookList.add(t);
    }

    public T getBookAt(int index){
        return this.bookList.get(index);
    }

    public int getLength(){
        return this.bookList.size();
    }


    @Override
    public Iterator<T> iterator() {
        if (iterator == null) {
            iterator = new BookShelfListIterator<T>(this);
        }
        return iterator;
    }
}
